#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/12/27 20:21
# @Author  : Sun
# @File    : modify_family_note.py
# @Software: PyCharm
import json

import requests

from common.mis_login import MisLogin
from common.read_yaml import ReadYaml
from common.write_log import WriteLog


class QueryGrow:
    _URL = "https://mis.jjmatch.cn/oms/evt_v2/api//common/GrowValueQueryEdit/websvrrest_devtest_query_evt_by_eid"
    _DATA = {
        "p_eid_list": "60000767",
        "p_userid_list": None,
        "p_nickname_list": ""
    }
    _HEADERS = {
        'content-type': 'application/json',
        'sec-fetch-site': 'same-origin',
        'sec-fetch-mode': 'cors',
        'sec-fetch-dest': 'empty',
        'referer': 'https://mis.jjmatch.cn/oms/evt_v2/Views/EventGrowSearch.html?bID=9449'
    }

    # _COOKIE = MisLogin().mis_login()
    try:
        _COOKIE = dict(ReadYaml().read_yaml('./config/mis_cookie.yaml'))
    except TypeError:
        MisLogin().mis_login()
        _COOKIE = dict(ReadYaml().read_yaml('./config/mis_cookie.yaml'))

    def query_grow(self, userid):
        WriteLog().write_log().info(self._COOKIE)
        self._DATA['p_userid_list'] = userid
        r = requests.request(
            data=json.dumps(
                self._DATA),
            method='POST',
            url=self._URL,
            headers=self._HEADERS,
            cookies=self._COOKIE)
        result = json.dumps(r.json(), ensure_ascii=False, indent=4)
        # print(result)
        WriteLog().write_log().info(result)
        grow_value = r.json()['data']['rows'][0]['p_value']
        WriteLog().write_log().info(grow_value)
        return grow_value


if __name__ == '__main__':
    QueryGrow().query_grow(userid="106146479")
